# import json
import os

from openpyxl import load_workbook
from openpyxl.utils import get_column_letter
from datetime import datetime

from openpyxl.workbook import Workbook
import math

# 假设 UWB_LOC_EARTH_RADIUS 和 RAD2DEG 是常量
UWB_LOC_EARTH_RADIUS = 6371000  # 地球半径，单位为米
DEG2RAD = math.pi / 180  # 度转弧度的转换因子

class TUWBLocXYZ:
    def __init__(self, x, y, z):
        self.x = x
        self.y = y
        self.z = z

class TUWBLocLLA:
    def __init__(self, lat, lon, alt):
        self.lat = lat
        self.lon = lon
        self.alt = alt

class Instance:
    def __init__(self, xyz_origin, lla_origin):
        self.xyz_origin = xyz_origin
        self.lla_origin = lla_origin

def uwb_loc_lla2xyz(lla, instance):
    delta_N = (lla.lat - instance.lla_origin.lat) * DEG2RAD * UWB_LOC_EARTH_RADIUS
    delta_E = (lla.lon - instance.lla_origin.lon) * DEG2RAD * UWB_LOC_EARTH_RADIUS

    xyz = TUWBLocXYZ(
        instance.xyz_origin.x + delta_E,
        instance.xyz_origin.y + delta_N,
        lla.alt  # 默认高度与海拔一致
    )

    return xyz

# 示例用法
xyz_origin = TUWBLocXYZ(0, 0, 0)
lla_origin = TUWBLocLLA(30.398608, 120.488824, 0)
instance = Instance(xyz_origin, lla_origin)

lla = TUWBLocLLA(30.400000, 120.480000, 10)

xyz = uwb_loc_lla2xyz(lla, instance)
print(f"x: {xyz.x}, y: {xyz.y}, z: {xyz.z}")
# def append_to_excel(data, filename):
#     # 加载现有的Workbook对象
#     # 检查文件是否存在
#     if not os.path.exists(f'./report/{filename}'):
#         # 文件不存在，创建一个新的Workbook对象
#         wb = Workbook()
#     else:
#         # 文件存在，加载现有的Workbook对象
#         wb = load_workbook(filename)
#
#     # 获取当前日期并格式化为 'YYYY-MM-DD'
#     current_date = datetime.now().strftime('%Y-%m-%d')
#
#     # 创建一个新的工作表，并以当前日期命名（如果已存在则不创建）
#     if current_date not in wb.sheetnames:
#         ws = wb.create_sheet(title=current_date)
#     else:
#         ws = wb[current_date]
#
#     # 获取当前工作表的最大行数
#     max_row = ws.max_row
#
#     # 追加数据
#     for row_index, row_data in enumerate(data, start=max_row + 1):   #用enumerate枚举法 将data里面的数据已max_row+1这个index为起点 给没个data里的行一个index
#         for col_index, cell_data in enumerate(row_data, start=1): #把一行又分为几列写入
#             # 获取列字母
#             col_letter = get_column_letter(col_index)
#             # 写入数据
#             ws[f"{col_letter}{row_index}"] = cell_data   #确定位置后写入
#
#     # 保存文件
#     path = os.path.dirname(__file__)
#     print(path)
#     wb.save(f'../report/{filename}')
#
# # 示例数据
# data = [
#     ["Eva", 28, "Female"],
#     ["Michael", 35, "Male"]
# ]
#
# # 文件名
# filename = "example.xlsx"
#
# # 调用函数追加写入数据到Excel文件
# append_to_excel(data, filename)


# import os
# from datetime import datetime
#
# #path = os.path.dirname(__file__)
#
# # 获取当前日期并格式化为文件夹名称格式，例如 '2024-03-12'
# current_date = datetime.now().strftime('%Y-%m-%d')
# folder_name = f'{current_date}_folder'
#
# # 创建文件夹
# os.makedirs(folder_name, exist_ok=True)
#
# # 在文件夹中创建1.txt文件
# file_path = os.path.join(folder_name, '1.txt')
# with open(file_path, 'w') as file:
#     file.write('')  # 写入空字符串，创建文件
#
# print(f'文件夹 "{folder_name}" 和文件 "1.txt" 已成功创建。')

# import requests
#
# url = "https://gwzaapp.com/api/uploadFile"
#
# payload = {'path': '21/memberPhotos/',
# 'ifDetectorFlag': 'false',
# 'memberId': '0'}
# files=[
#   ('files',('user.png',open('user.png','rb'),'image/png'))
# ]
# headers = {
#   'Accept': 'application/json, text/plain, */*',
#   'Accept-Language': 'zh-CN,zh;q=0.9',
#   'Authorization': 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjY5ZjU4YjUxLWY2ODYtNDZmYS1hNDA2LTg4YjI0MDFkNjk1OCJ9.7r7wlv-ZdLEGpzhk1uI_PDTuYwtyQTTqvFhoJ1wzAGfG-MmZMcKTzupRUlAL7zy5ZMQsDhMMDJ8nHxY7xB1DdQ',
#   'Connection': 'keep-alive',
#   'Cookie': 'username=admin; rememberMe=true; password=K7xdHphxrCDmLy9LpK8brY8EZE5sS10tPwRWd1LIX76irjVlZZHB2ocUAeObFG5yhc6JO/vVND5Vu0NSTDkDTw==; Admin-Token=eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjY5ZjU4YjUxLWY2ODYtNDZmYS1hNDA2LTg4YjI0MDFkNjk1OCJ9.7r7wlv-ZdLEGpzhk1uI_PDTuYwtyQTTqvFhoJ1wzAGfG-MmZMcKTzupRUlAL7zy5ZMQsDhMMDJ8nHxY7xB1DdQ; sidebarStatus=0',
#   'Origin': 'https://gwzaapp.com',
#   'Referer': 'https://gwzaapp.com/peopleManage/member',
#   'Sec-Fetch-Dest': 'empty',
#   'Sec-Fetch-Mode': 'cors',
#   'Sec-Fetch-Site': 'same-origin',
#   'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
#   'sec-ch-ua': '"Chromium";v="122", "Not(A:Brand";v="24", "Google Chrome";v="122"',
#   'sec-ch-ua-mobile': '?0',
#   'sec-ch-ua-platform': '"Windows"'
# }
#
# response = requests.request("POST", url, headers=headers, data=payload, files=files)
#
# print(response.text)

# # 给定的模板字符串
# # payload_str = ('{{"searchValue":null,"createBy":"admin","createTime":"2023-12-15 16:43:25",'
# #                '"updateBy":null,"updateTime":"2023-12-15 17:30:07","remark":null,"beginTime":null,"endTime":null,"params":{{}},"actionType":null,"rowNum":null,"pushFlag":0,"userId":853,"pushId":null,"roleId":null,"roleKey":null,"loginName":null,"memberId":"900000202312181055","deptId":null,"userName":"{username}","ifUpdateRoles":null,"nickName":"夏测试2","email":"","phonenumber":"{phonenumber}","companyName":" ","sex":"1","avatar":"","salt":null,"status":"0","delFlag":"0","loginIp":"","loginDate":null,"roles":[43,55,97,133,139,229,241,253,259,271,277,283,289],"roleIds":[6,43,55,97,133,139,229,241,253,259,271,277,283,289],"admin":false,"password":"","largeRoles":[10]}}')
# #
# # # 要替换的参数
# # username = "夏双手合十"
# # phonenumber = "123456789"
# #
# # # 使用字符串格式化将参数替换为模板字符串中的相应位置
# # formatted_payload_str = payload_str.format(username=username, phonenumber=phonenumber)
#
# payload = (
#             '{{"searchValue":null,"createBy":"admin","createTime":"2023-12-15 16:43:25","updateBy":null,"updateTime":"2023-12-15 17:30:07","remark":null,"beginTime":null,"endTime":null,"params":{{}},'
#             '"actionType":null,"rowNum":null,"pushFlag":0,"userId":{useId},"pushId":null,"roleId":null,"roleKey":null,"loginName":null,"memberId":{memberId},"deptId":null,"userName":"{userName}",'
#             '"ifUpdateRoles":null,"nickName":{nickName},"email":"","phonenumber":"{phonenumber}","companyName":" ","sex":"1","avatar":"","salt":null,"status":"0","delFlag":"0","loginIp":"","loginDate":null,'
#             '"roles":{roles},"roleIds":{roleIds},"admin":false,"password":"","largeRoles":[10]}}')
#
# useId = 850
# memberId = '900000202312181052'
# userName = '13735438001_U'
# nickName = "夏"
# phoneNumber = '13735438001'
# roles = [31,43,115,193,277,283,331,349]
# roleIds = [10,31,43,115,193,277,283,331,349]
# #payload_str = payload.format(nickName=json.dumps(nickName, ensure_ascii=False))
# payload_str = payload.format(useId=useId, memberId=memberId, roles=roles, roleIds=roleIds, userName=userName, phonenumber=phoneNumber,nickName=json.dumps(nickName, ensure_ascii=False))
#
# payload_json = json.loads(payload_str)
# payload_str = json.dumps(payload_json, ensure_ascii=False)
#
#
# print(payload_str)
#
# a = "你"
# print(format(ord(a)))
#
# chinese_text = "你好世界"  # 这里是一个中文字符串示例
# unicode_escaped = chinese_text.encode('unicode_escape')
# print(unicode_escaped)
#
# # 使用列表推导式和字符串格式化将每个字符转义为 Unicode 码点
# unicode_escaped = ''.join([f'\\u{ord(char):04x}' for char in chinese_text])
#
# # 输出转义后的字符串
# print(unicode_escaped)
# phoneNumber= "1223444"
# print("/list?pageNum=1&pageSize=10&nickName=&phonenumber={}&beginTime=&endTime=".format(phoneNumber))
#
# # 解析成 JSON 对象
# #payload_json = json.loads(formatted_payload_str)
#
# #print(payload_json)
import time
# from datetime import datetime
#
# print(datetime(2023, 12, 18, 16, 35, 16))
#
#
#
# a = ['1', 'b', 'c']
# b = ['c', '1']
#
# # 将两个数组转换为集合
# set_a = set(a)
# set_b = set(b)
#
# # 找到两个集合的差集
# result = set_a - set_b
#
# # 将结果转换回列表
# result_list = list(result)
#
# print("两个数组的相减部分:", result_list)

# arr =[]
# def a():
#     arr.append('1')
# def b():
#     arr.append('2')
#
# a()
# b()
# print(arr)